﻿Public Class TiledBackgroundTile
    Private _Background As TiledBackground
    Public ReadOnly Property Background As TiledBackground
        Get
            Return _Background
        End Get
    End Property

    Public Property Passable As TilePassageLayer
    Public Property TileId As Integer
    Public Property TileSheetLocation As Point
    Public Property TileSheetName As String
    Public Property SourceTileSize As Size

    Public Sub New(parent As TiledBackground)
        _Background = parent
        SourceTileSize = _Background.TileSize
    End Sub

    Protected Friend Sub OnDraw(e As DrawEventArgs, mapX As Integer, mapY As Integer)
        Dim sourceImage As Bitmap = e.Engine.CurrentScene.GetImageAsset(TileSheetName)
        Dim sourceBounds As Rectangle = New Rectangle(TileSheetLocation, SourceTileSize)
        Dim tileSize As Size = _Background.TileSize
        Dim destinationBounds As Rectangle = New Rectangle(mapX * tileSize.Width, mapY * tileSize.Height, tileSize.Width, tileSize.Height)
        e.PaintEventArgs.Graphics.DrawImage(sourceImage, destinationBounds, sourceBounds, GraphicsUnit.Pixel)
    End Sub
End Class